package sort;

import org.junit.Test;

/**
 * @author futao
 * Created on 18-3-12-上午10:08.
 */
public class Sort {
    @Test
    public void sort() {
        int[] array = new int[]{1, 50, 3, 55, 6, 99};

        for (int i = array.length - 1; i > 0; i--) {
            for (int j = 1; j < i; j++) {
                if (array[j] > array[j + 1]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }

        for (int a : array) {
            System.out.println(a);
        }
    }


    /**
     * 冒泡排序
     */
    @Test
    public void sort2() {
        int[] array = new int[]{1, 50, 3, 55, 6, 99};
        for (int i = 0; i < array.length; i++) {
            for (int j = i; j < array.length - i - 1; j++) {
                if (array[j] > array[j + 1]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }
        for (int a : array) {
            System.out.println(a);
        }
    }

    private static String reverse(String originStr) {
        if (originStr == null || originStr.length() == 1) {
            return originStr;
        }
        System.out.println("---" + originStr.substring(1));
        System.out.println("===" + originStr.charAt(0));
        return reverse(originStr.substring(1)) + originStr.charAt(0);
    }

    public static void main(String[] args) {
        System.out.println(reverse("hello"));
    }
}
